package com.shhm.filter;

import com.shhm.common.utils.JwtUtil;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/7 下午5:34
 */
public class JwtSecurityFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
//        String token = JwtUtil.handleAuthorizationString(request.getHeader("Authorization"));
//        if (token != null && !JwtUtil.validateToken(token).equals("pass")) {
//            // 创建认证对象
//            UserDetails user = userService.loadUserByUsername(JwtUtil.getUsernameFromToken(token));
//            Authentication auth = new UsernamePasswordAuthenticationToken(
//                    user, null, user.getAuthorities());
//
//            // 关键：设置安全上下文
//            SecurityContextHolder.getContext().setAuthentication(auth);
//        }
        filterChain.doFilter(request, response);
    }
}
